﻿using Biomedica.Graphics;
using Biomedica.Propability.StateMachine;
using KinectWindows.Nui.Nui.Postures;
using Microsoft.Kinect;
using NuiDicomPlayer.Nui.Gestures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NuiDicomPlayer.Nui.NavigationEngine
{
    public class BothHandsBetweenHeadAndSpineDetector : PostureDetectorBase
    {
        private bool detected;
       
        public BothHandsBetweenHeadAndSpineDetector(StateContext Context):base(10,Context)
        {
      

        }

        public void TrackPosture(Vector3 head, Vector3 Spine, Vector3 lefthand, Vector3 righthand)
        {
            TrackPosture(new Vector3[] { head, Spine, lefthand, righthand });
        }

        public override void TrackPosture(Vector3[] jointsPos)
        {
            Vector3 head = jointsPos[0];
            Vector3 spine = jointsPos[1];
            Vector3 lefthand = jointsPos[2];
            Vector3 righthand = jointsPos[3];
            
            if(ChekIsinZone(head,spine,lefthand,righthand))
                RaisPostureDetected("BothHandsBetweenHeadAndSpine");

            Reset();
        }

        private bool ChekIsinZone(Vector3 head, Vector3 spine, Vector3 lefthand, Vector3 righthand)
        {
            if (!head.HasValue || !spine.HasValue || !lefthand.HasValue || !righthand.HasValue) return false;
            if (lefthand.Y > head.Y || lefthand.Y < spine.Y) return false;            
            if (righthand.Y > head.Y || righthand.Y < spine.Y) return false;
            return true;
        }
    }
}

